package dd.view;

import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import dd.control.addEdgemouseController;
import dd.model.Event;
import dd.model.Model;

public class addEdgeFrame extends JFrame {

	JPanel contentPane;
	DrawingCanvas canvas;
	JLabel lblFdf;
	Event event;
	JLabel lblOpenModePlease;

	/**
	 * Create the frame.
	 */
	public addEdgeFrame() {
		setTitle("Add Edges Frame");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 651, 468);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		Model model = Model.getInstance();
		Event event = model.getEvent();

		canvas = new DrawingCanvas(event);
		if (event.getIsYourturn()) {
			canvas.addMouseListener(new addEdgemouseController(this));
		}
		canvas.setBounds(10, 100, 560, 393);
		contentPane.add(canvas);

		JLabel lblEventName = new JLabel(event.getEventName() + " position: " + event.getPostion());
		lblEventName.setBounds(68, 11, 393, 29);
		lblEventName.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblEventName.setHorizontalAlignment(SwingConstants.CENTER);
		// getContentPane().add(lblEventName);
		contentPane.add(lblEventName);

		lblOpenModePlease = new JLabel();
		lblOpenModePlease.setBounds(171, 51, 500, 14);
		lblOpenModePlease.setHorizontalAlignment(SwingConstants.CENTER);
		contentPane.add(lblOpenModePlease);
		if (event.getIsYourturn()) {
			lblOpenModePlease.setText("It's your turn!");
		} else {
			lblOpenModePlease.setText("Wariting for your turn");
		}

		lblFdf = new JLabel("Left edges: " + event.getleftEdges() + "");
		lblFdf.setBounds(200, 86, 122, 14);
		lblFdf.setHorizontalAlignment(SwingConstants.CENTER);
		// getContentPane().add(lblFdf);
		contentPane.add(lblFdf);
		JLabel lblEventId = new JLabel("Event ID: " + event.getEventID());
		lblEventId.setBounds(378, 86, 100, 14);
		// getContentPane().add(lblEventId);
		contentPane.add(lblEventId);
		model.setaef(this);
	}

	public void redraw() {
		canvas.repaint();
	}

	public void repaint() {
		Model model = Model.getInstance();
		Event event = model.getEvent();
		lblFdf.setText("Left edges: " + event.getleftEdges() + "");
		if (event.getleftEdges() == 0) {
			lblOpenModePlease.setText("Your turn is over, please wait for admin's operation!");
		} else if (event.getIsYourturn()) {
			lblOpenModePlease.setText("It's your turn!");
		} else {
			lblOpenModePlease.setText("Waiting...");
		}
		contentPane.updateUI();
	}

	public DrawingCanvas getDrawingCanvas() {
		return canvas;
	}

	public JLabel getLblOpenModePlease() {
		return lblOpenModePlease;
	}

}
